/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using FITHOU.DO;
/// <summary>
/// Summary description for tbl_TuDienDAL
/// </summary>
namespace FITHOU.DAL
{

    public class tbl_TuDienDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public tbl_TuDienDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(tbl_TuDienDO objtbl_TuDienDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@TA", SqlDbType.NText);
            Sqlparam.Value = objtbl_TuDienDO.TA;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TV", SqlDbType.NText);
            Sqlparam.Value = objtbl_TuDienDO.TV;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(tbl_TuDienDO objtbl_TuDienDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objtbl_TuDienDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TA", SqlDbType.NText);
            Sqlparam.Value = objtbl_TuDienDO.TA;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TV", SqlDbType.NText);
            Sqlparam.Value = objtbl_TuDienDO.TV;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(tbl_TuDienDO objtbl_TuDienDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objtbl_TuDienDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public tbl_TuDienDO Select(int id)
        {
            tbl_TuDienDO objtbl_TuDienDO = new tbl_TuDienDO();
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = id;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objtbl_TuDienDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["TA"]))
                    objtbl_TuDienDO.TA = Convert.ToString(dr["TA"]);
                if (!Convert.IsDBNull(dr["TV"]))
                    objtbl_TuDienDO.TV = Convert.ToString(dr["TV"]);

            }
            return objtbl_TuDienDO;
        }

        public tbl_TuDienDO SelectByTA(string ta)
        {
            tbl_TuDienDO objtbl_TuDienDO = new tbl_TuDienDO();
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetByTA";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ta", SqlDbType.NText);
            Sqlparam.Value = ta;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objtbl_TuDienDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["TA"]))
                    objtbl_TuDienDO.TA = Convert.ToString(dr["TA"]);
                if (!Convert.IsDBNull(dr["TV"]))
                    objtbl_TuDienDO.TV = Convert.ToString(dr["TV"]);

            }
            return objtbl_TuDienDO;
        }

        public tbl_TuDienDO SelectByTV(string ta)
        {
            tbl_TuDienDO objtbl_TuDienDO = new tbl_TuDienDO();
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetByTV";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@tv", SqlDbType.NText);
            Sqlparam.Value = ta;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objtbl_TuDienDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["TA"]))
                    objtbl_TuDienDO.TA = Convert.ToString(dr["TA"]);
                if (!Convert.IsDBNull(dr["TV"]))
                    objtbl_TuDienDO.TV = Convert.ToString(dr["TV"]);

            }
            return objtbl_TuDienDO;
        }

        public tbl_TuDienDO Select(tbl_TuDienDO objtbl_TuDienDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objtbl_TuDienDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objtbl_TuDienDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["TA"]))
                    objtbl_TuDienDO.TA = Convert.ToString(dr["TA"]);
                if (!Convert.IsDBNull(dr["TV"]))
                    objtbl_TuDienDO.TV = Convert.ToString(dr["TV"]);

            }
            return objtbl_TuDienDO;
        }

        public tbl_TuDienDO getTop()
        {
            tbl_TuDienDO objtbl_TuDienDO = new tbl_TuDienDO();
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetTop";


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objtbl_TuDienDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["TA"]))
                    objtbl_TuDienDO.TA = Convert.ToString(dr["TA"]);
                if (!Convert.IsDBNull(dr["TV"]))
                    objtbl_TuDienDO.TV = Convert.ToString(dr["TV"]);

            }
            return objtbl_TuDienDO;
        }


        public tbl_TuDienDO SelectTV(tbl_TuDienDO objtbl_TuDienDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetByTV";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@tv", SqlDbType.NText);
            Sqlparam.Value = objtbl_TuDienDO.TV;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objtbl_TuDienDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["TA"]))
                    objtbl_TuDienDO.TA = Convert.ToString(dr["TA"]);
                if (!Convert.IsDBNull(dr["TV"]))
                    objtbl_TuDienDO.TV = Convert.ToString(dr["TV"]);

            }
            return objtbl_TuDienDO;
        }

        public tbl_TuDienDO SelectTA(tbl_TuDienDO objtbl_TuDienDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetByTA";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ta", SqlDbType.NText);
            Sqlparam.Value = objtbl_TuDienDO.TA;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objtbl_TuDienDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["TA"]))
                    objtbl_TuDienDO.TA = Convert.ToString(dr["TA"]);
                if (!Convert.IsDBNull(dr["TV"]))
                    objtbl_TuDienDO.TV = Convert.ToString(dr["TV"]);

            }
            return objtbl_TuDienDO;
        }


        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrtbl_TuDienDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    tbl_TuDienDO objtbl_TuDienDO = new tbl_TuDienDO();
                    if (!Convert.IsDBNull(dr["ID"]))
                        objtbl_TuDienDO.ID = Convert.ToInt32(dr["ID"]);
                    if (!Convert.IsDBNull(dr["TA"]))
                        objtbl_TuDienDO.TA = Convert.ToString(dr["TA"]);
                    if (!Convert.IsDBNull(dr["TV"]))
                        objtbl_TuDienDO.TV = Convert.ToString(dr["TV"]);
                    arrtbl_TuDienDO.Add(objtbl_TuDienDO);
                }
            }
            return arrtbl_TuDienDO;
        }

        public DataTable SelectAll()
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public tbl_TuDienDO SelectRandom()
        {
            tbl_TuDienDO objtbl_TuDienDO = new tbl_TuDienDO();
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetRandom";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    if (!Convert.IsDBNull(dr["ID"]))
                        objtbl_TuDienDO.ID = Convert.ToInt32(dr["ID"]);
                    if (!Convert.IsDBNull(dr["TA"]))
                        objtbl_TuDienDO.TA = Convert.ToString(dr["TA"]);
                    if (!Convert.IsDBNull(dr["TV"]))
                        objtbl_TuDienDO.TV = Convert.ToString(dr["TV"]);
                }
            }
            return objtbl_TuDienDO;
        }

        public DataTable SelectRandomDA(tbl_TuDienDO objtbl_TuDienDO)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetRandomDA";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objtbl_TuDienDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
            }
            return dt;
        }

        public DataTable SelectRandom4DA(tbl_TuDienDO objtbl_TuDienDO)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_TuDien_GetRandom4DA";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objtbl_TuDienDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
            }
            return dt;
        }

        #endregion

    }

}
